package com.wengu.rabbitmq.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;


/**
 * @author LoserJohn
 * @create 2020-09-07 10:50
 */
public class ConnectionUtil {
    //获取rabbitmq连接的方法
    public static Connection getConnection() throws IOException, TimeoutException {
        //1.创建mq的连接工厂对象配置连接参数
        ConnectionFactory factory = new ConnectionFactory();
        //mq的host地址
        factory.setHost("192.168.206.128");
        //mq的端口号
        factory.setPort(5672);
        //账号
        factory.setUsername("admin");
        //密码
        factory.setPassword("123456");
        //虚拟主机
        factory.setVirtualHost("/loser-vh");
        Connection connection = factory.newConnection();
        return connection;

    }
}
